package com.alpsot.spotcheck.activity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.text.method.DigitsKeyListener;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.alpsoft.spotcheck.adapter.CheckItemListViewAdapter;
import com.alpsoft.spotcheck.db.DBManager;
import com.alpsoft.spotcheck.db.SQLiteTemplate;
import com.alpsoft.spotcheck.db.SQLiteTemplate.RowMapper;
import com.alpsoft.spotcheck.model.EqResult;
import com.alpsoft.spotcheck.model.Exception;
import com.alpsoft.spotcheck.model.User;
import com.alpsoft.spotcheck.util.GlobalVar;
import com.alpsoft.spotcheck.util.SharedPreferencesUtils;
import com.alpsot.lkspotcheck.R;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

/** 
 * This example shows how to use choice mode on a list. This list is  
 * in CHOICE_MODE_MULTIPLE mode, which means the items behave like 
 * checkboxes. 
 */ 

@ContentView(R.layout.activity_item_listview)
public class CheckItemActivity extends BaseActivity {
	public static CheckItemActivity instance = null;
	private TextView tv;
	private ListView listview;
	static int listViewPos;
	static List<Map<String, Object>> listData = new ArrayList<Map<String, Object>>();
	static SimpleAdapter listAdapter;
	private String record_id;
	private SQLiteTemplate st;
	private DBManager dbManager;
	private Integer exp_id;
	private String empId;
	static Map temMap;
	private String tabCode;
	String belongEq;
	String cycle_type;
	private String isCheckMan;
	private View v;
	
	@ViewInject(R.id.item_save)
	private Button item_save;
	@ViewInject(R.id.item_back)
	private Button item_back;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ViewUtils.inject(this);
		instance = this;
		User user = SharedPreferencesUtils.getLoginInfo(this);
		empId = user.getUserId();
		dbManager = DBManager.getInstance(this, GlobalVar.databaseName);
		Intent intent = this.getIntent();//得到激活她的意图  
        belongEq = intent.getStringExtra("belongEq");  
        cycle_type = intent.getStringExtra("cycle_type");
        tabCode = intent.getStringExtra("tab_code");
        isCheckMan = intent.getStringExtra("isCheckMan");
        if("true".equals(isCheckMan)){
        	item_back.setVisibility(View.GONE);
        }else if("false".equals(isCheckMan)){
        	item_save.setVisibility(View.GONE);
        }
        
		listData = getData(cycle_type,belongEq);
        
        listAdapter = new CheckItemListViewAdapter(this, listData, 
                R.layout.activity_item,new String[] { "item","show","standard"}, 
                new int[] { R.id.check_item,R.id.check_result,R.id.standard });
        listview = (ListView)this.findViewById(R.id.itemlistview); 
        listview.setAdapter(listAdapter); 

        listview.setOnItemClickListener(new OnItemClickListener() {
        	@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
        		listViewPos = position;
        		temMap = listData.get(listViewPos);
//        		tv = (TextView) view.findViewById(R.id.check_result);
        		HashMap<String,Object> map = (HashMap<String, Object>) listview.getItemAtPosition(position);
//        		final String result = tv.getText().toString();
        		final String result = (String)temMap.get("it_type");
        		final String equipment_id = (String) map.get("equipment_id");
				record_id = (String) map.get("check_record_id");
				if(null==record_id||"".equals(record_id)){
		        	//点检项目对应的所有点击记录已过期的情况
					Toast toast = Toast.makeText(getApplicationContext(),
					"无对应点检记录", Toast.LENGTH_LONG);
					toast.setGravity(Gravity.CENTER, 0, 0);
					toast.show();
		        }else if("√".equals(result)){	
                	//跳转到异常处理页面
		        	if("true".equals(isCheckMan)){
	        			temMap.put("it_type", "╳");
	        			temMap.put("show", "╳");
	        			temMap.put("is_exception", "yes");
	    				listAdapter.notifyDataSetChanged();
	    				exp_id = insertExp(equipment_id);
	    				Intent intent = new Intent();
	    				intent.putExtra("exp_id", exp_id.toString());
	    				intent.putExtra("isCheckMan", isCheckMan);
	    				intent.setClass(CheckItemActivity.this, ExceptionActivity.class); 
	    				startActivity(intent);  
		        	}
                } else if("╳".equals(result)){ 
                	if("true".equals(isCheckMan)){
                		onSelected(tv);
                    }else if("false".equals(isCheckMan)){
                    	Intent intent = new Intent(); 
        		    	if(exp_id==null){
        		    		String exp_id_Str = getExpId(record_id);
        			    	exp_id = Integer.valueOf(exp_id_Str);
        		    	}
        		    	intent.putExtra("exp_id", exp_id.toString());
        		    	intent.putExtra("isCheckMan", isCheckMan);
        				intent.setClass(CheckItemActivity.this, ExceptionActivity.class); 
        				startActivityForResult(intent, 1);
                    }
                	
                } else{
                	String is_exception = (String)temMap.get("is_exception");
                	if(!"yes".equals(is_exception)&&"true".equals(isCheckMan)){
                		inputJudge(result, equipment_id);
                	}else if("yes".equals(is_exception)&&"true".equals(isCheckMan)){
                		new AlertDialog.Builder(CheckItemActivity.this).setTitle("如要查看异常，点击查看;如要重新输入数据，点击更改")  
    					.setIcon(android.R.drawable.ic_dialog_info)
    					.setCancelable(false)
    					.setPositiveButton("查看", new DialogInterface.OnClickListener() {  
    					  
    						@Override  
    						public void onClick(DialogInterface dialog, int which) {  
    							// 点击“查看”后的操作,跳转到异常处理页面
    							Intent intent = new Intent(); 
    					    	if(exp_id==null){
    					    		String exp_id_Str = getExpId(record_id);
    						    	exp_id = Integer.valueOf(exp_id_Str);
    					    	}
    					    	intent.putExtra("exp_id", exp_id.toString());
    					    	intent.putExtra("belongEq", belongEq);
    					    	intent.putExtra("cycle_type", cycle_type);
    					    	intent.putExtra("isCheckMan", isCheckMan);
    					    	intent.putExtra("position", String.valueOf(listViewPos));
    							intent.setClass(CheckItemActivity.this, ExceptionActivity.class); 
    							startActivityForResult(intent, 1);
    						}  
    					})  
    					.setNegativeButton("更改", new DialogInterface.OnClickListener() {  
    					  
    						@Override  
    					 	public void onClick(DialogInterface dialog, int which) {  
    							// 点击“更改”后的操作
    							clearExceptionInfo();
    							inputJudge(result, equipment_id);
    						}  
    					}).show(); 
                	}else if("yes".equals(is_exception)&&"false".equals(isCheckMan)){
                		Intent intent = new Intent(); 
				    	if(exp_id==null){
				    		String exp_id_Str = getExpId(record_id);
					    	exp_id = Integer.valueOf(exp_id_Str);
				    	}
				    	intent.putExtra("exp_id", exp_id.toString());
				    	intent.putExtra("belongEq", belongEq);
				    	intent.putExtra("cycle_type", cycle_type);
				    	intent.putExtra("isCheckMan", isCheckMan);
				    	intent.putExtra("position", String.valueOf(listViewPos));
						intent.setClass(CheckItemActivity.this, ExceptionActivity.class); 
						startActivityForResult(intent, 1);
                	}
            		
                }  
			}

			private void inputJudge(final String result,
					final String equipment_id) {
				final EditText inputServer = new EditText(CheckItemActivity.this);
				inputServer.setText(result);
				inputServer.setFocusable(true);
				inputServer.selectAll();
				inputServer.setKeyListener(new DigitsKeyListener(true,true));
				AlertDialog.Builder builder = new AlertDialog.Builder(CheckItemActivity.this);
				builder.setTitle("请输入数值").setCancelable(false).setIcon(android.R.drawable.ic_dialog_info)
				.setView(inputServer).setPositiveButton("Ok", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						String con = inputServer.getText().toString();
						if(!TextUtils.isEmpty(con)){
							Map map = listData.get(listViewPos);
							map.put("it_type", con);
							map.put("show", con + map.get("unit"));
							listAdapter.notifyDataSetChanged();
							//增加上下限判断
							Object downValObj = map.get("down_value");
							Object upValObj = map.get("up_value");
							Boolean isLegal = judgeScope(con, downValObj, upValObj);
							if(!isLegal){
								new AlertDialog.Builder(CheckItemActivity.this).setTitle("数值越界！如为异常情况，点击异常;如为正常情况，点击确定!")  
								.setIcon(android.R.drawable.ic_dialog_info)
								.setCancelable(false)
								.setPositiveButton("异常", new DialogInterface.OnClickListener() {  
								  
									@Override  
									public void onClick(DialogInterface dialog, int which) {  
										// 点击“异常”后的操作,跳转到异常处理页面
										Map map = listData.get(listViewPos);
						        		map.put("is_exception", "yes");
						        		listAdapter.notifyDataSetChanged();
						        		
								    	Intent intent = new Intent(); 
								    	exp_id = insertExp(equipment_id);
//	                					    	if(exp_id==null){
//	                					    		String exp_id_Str = getExpId(record_id);
//	                						    	exp_id = Integer.valueOf(exp_id_Str);
//	                					    	}
								    	intent.putExtra("exp_id", exp_id.toString());
								    	intent.putExtra("belongEq", belongEq);
								    	intent.putExtra("cycle_type", cycle_type);
								    	intent.putExtra("isCheckMan", isCheckMan);
								    	intent.putExtra("position", String.valueOf(listViewPos));
//	                					    	LogUtils.i(String.valueOf(listViewPos));
										intent.setClass(CheckItemActivity.this, ExceptionActivity.class);
										startActivityForResult(intent, 1);
//	                							startActivity(intent);
									}  
								})  
								.setNegativeButton("确认", new DialogInterface.OnClickListener() {  
								  
									@Override  
								 	public void onClick(DialogInterface dialog, int which) {  
										// 点击“确认”后的操作
						        		Map map = listData.get(listViewPos);
						        		map.put("is_exception", "no");
						        		listAdapter.notifyDataSetChanged();
//						        		clearExceptionInfo();
									}  
								}).show(); 
							}else{
								Toast toast = Toast.makeText(getApplicationContext(),
										"请输入数值", Toast.LENGTH_LONG);
								toast.setGravity(Gravity.CENTER, 0, 0);
								toast.show();
								map.put("is_exception", "no");
					    		listAdapter.notifyDataSetChanged();
					    		clearExceptionInfo();
							}
						}else{
							Toast toast = Toast.makeText(getApplicationContext(),
									"请输入数值", Toast.LENGTH_LONG);
							toast.setGravity(Gravity.CENTER, 0, 0);
							toast.show();
						}
					}
				});
				builder.show();
			}

		});
	}

	@Override
	public Handler getHandler() {
		return null;
	}

	private List<Map<String, Object>> getData(String cycle_type, String belongEq) {
		
		DBManager dbManager = DBManager.getInstance(this, GlobalVar.databaseName);
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		String now = sdf.format(new Date());
//		
//        Calendar cal = Calendar. getInstance ();
//        cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) + 1);
//        String oneHoursAfter = sdf.format(cal.getTime());//获取到完整的时间
		
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT F.*,G.END_TIME END_TIME,G.CHECK_RECORD_ID CHECK_RECORD_ID,G.IS_EXCEPTION IS_EXCEPTION,G.CHECK_RESULT CHECK_RESULT ");
		sb.append("FROM EQ_EQUIPMENT E,EQ_CHECK_ITEM F,EQ_CHECK_RECORD G ");
		sb.append("WHERE F.EQUIPMENT_ID = E.EQUIPMENT_ID and F.CHECK_ITEM_ID = G.CHECK_ITEM_STRATEGY_ID ");
		sb.append("and F.CYCLE_TYPE = ? and F.EQUIPMENT_ID = ? ");
        sb.append("and ((datetime(G.START_TIME)<datetime('now','localtime') and datetime(G.END_TIME)>datetime('now','localtime') and F.CYCLE_UNIT != 'day') or F.CYCLE_UNIT = 'day' or F.CYCLE_UNIT = 'week') ");
        sb.append("order by ITEM_TYPE,UNIT,ITEM_CONTENT,CHECK_ITEM_ID");
		
        st = SQLiteTemplate.getInstance(dbManager, false);
		List<EqResult> EqResultList = st.queryForList(new RowMapper<EqResult>() {

			@Override
			public EqResult mapRow(Cursor cursor, int index) {
				EqResult eq = new EqResult();
				eq.setItem_content(cursor.getString(cursor.getColumnIndex("ITEM_CONTENT")));
				eq.setItem_type(cursor.getString(cursor.getColumnIndex("ITEM_TYPE")));
				eq.setUnit(cursor.getString(cursor.getColumnIndex("UNIT")));
				eq.setDown_value(cursor.getString(cursor.getColumnIndex("DOWN_VALUE")));
				eq.setUp_value(cursor.getString(cursor.getColumnIndex("UP_VALUE")));
				eq.setStandard(cursor.getString(cursor.getColumnIndex("STANDARD")));
				eq.setItem_fn(cursor.getString(cursor.getColumnIndex("ITEM_FN")));
				eq.setCheck_item_id(cursor.getString(cursor.getColumnIndex("CHECK_ITEM_ID")));
				eq.setEquipmentid(cursor.getString(cursor.getColumnIndex("EQUIPMENT_ID")));
				eq.setEnd_time(cursor.getString(cursor.getColumnIndex("END_TIME")));
				eq.setCheck_record_id(cursor.getString(cursor.getColumnIndex("CHECK_RECORD_ID")));
				eq.setIs_exception(cursor.getString(cursor.getColumnIndex("IS_EXCEPTION")));
				eq.setCheck_result(cursor.getString(cursor.getColumnIndex("CHECK_RESULT")));
				eq.setCycle_type(cursor.getString(cursor.getColumnIndex("CYCLE_TYPE")));
				return eq;
			}
			
		}, sb.toString(), new String[]{cycle_type,belongEq});
		
		listData.clear();
 
		for(EqResult eq:EqResultList){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("item", eq.getItem_content());
			map.put("item_type", eq.getItem_type());
			map.put("unit", eq.getUnit());
			map.put("down_value", eq.getDown_value());
			map.put("up_value", eq.getUp_value());
			map.put("standard", eq.getStandard());
			map.put("item_fn", eq.getItem_fn());
			map.put("check_item_id", eq.getCheck_item_id());
			map.put("equipment_id", eq.getEquipmentid());
			map.put("check_record_id", eq.getCheck_record_id());
			map.put("end_time", eq.getEnd_time());
			map.put("is_exception", eq.getIs_exception());
			map.put("check_result", eq.getCheck_result());
			map.put("cycle_type",eq.getCycle_type());
			
			listData.add(map);
		}
		
		for(Map<String, Object> map:listData){
        	if("dl".equals(map.get("item_type"))){//定量
        		if(null!=map.get("check_result")){
        			map.put("it_type", map.get("check_result"));
        			map.put("show", (String)map.get("check_result") + (String)map.get("unit"));
        		}else{
        			map.put("it_type", "");
        			map.put("show", (String)map.get("unit"));
        		}
        	}else if("dx".equals(map.get("item_type"))){//定性
        		String is_exp = (String)map.get("is_exception");
        		if("yes".equals(is_exp)){
        			map.put("it_type", "╳");
        			map.put("show", "╳");
        		}else{
        			map.put("it_type", "√");
        			map.put("show", "√");
        		}
        	}
        }
        return listData; 
		
	}
	
	private void onSelected(final TextView tv) {
		// TODO Auto-generated method stub
		AlertDialog dialog = new AlertDialog.Builder(this).setTitle("如查看异常，点击查看;如删除异常信息，点击删除!")  
		.setIcon(android.R.drawable.ic_dialog_info)
		.setCancelable(false)
		.setPositiveButton("查看", new DialogInterface.OnClickListener() {  
		  
			@Override  
			public void onClick(DialogInterface dialog, int which) {  
				// 点击“查看”后的操作,跳转到异常处理页面
		    	Intent intent = new Intent(); 
		    	if(exp_id==null){
		    		String exp_id_Str = getExpId(record_id);
			    	exp_id = Integer.valueOf(exp_id_Str);
		    	}
		    	intent.putExtra("exp_id", exp_id.toString());
		    	intent.putExtra("isCheckMan", isCheckMan);
				intent.setClass(CheckItemActivity.this, ExceptionActivity.class); 
				startActivity(intent);
			}  
		})  
		.setNegativeButton("删除", new DialogInterface.OnClickListener() {  
		  
			@Override  
		 	public void onClick(DialogInterface dialog, int which) {  
				// 点击“确认”后的操作
		    	temMap=listData.get(listViewPos);
    			temMap.put("it_type", "√");
    			temMap.put("show", "√");
    			temMap.put("is_exception", "no");
				listAdapter.notifyDataSetChanged();
		    	clearExceptionInfo();
			}

		}).show(); 
	}
	
	private Integer insertExp(String equipment_id) {
		StringBuilder sb = new StringBuilder();
		sb.append("insert into RP_EXCEPTION_SUBMIT (RESOURCE_TYPE,RESOURCE_ID,SUBMIT_USER_ID,EQUIPMENT_ID) ");
		sb.append("VALUES ");
		sb.append("(?,?,?,(select SELF_CODE from EQ_EQUIPMENT where EQUIPMENT_ID=?))");
		SQLiteDatabase dataBase = dbManager.openDatabase();
		dataBase.execSQL(sb.toString(), new Object[]{"dj",record_id, empId, equipment_id });
		Integer insertId = st.getLastInsertId(dataBase, "RP_EXCEPTION_SUBMIT");
		return insertId;
	}
	
	@OnClick(R.id.item_back)
	private void back(View v){
		Intent intent = new Intent();  
        intent.putExtra("tabCode", tabCode);  
        setResult(2, intent);  
        finish();  
	}
	//保存按钮
	@OnClick(R.id.item_save)
	private void save(View v){
		boolean flag=true;
		for(Map<String, Object> m:listData){
			String it_type_test = (String)m.get("it_type"); 
			if(TextUtils.isEmpty(it_type_test)){
				flag=false;
				break;
			}
		}
		if(flag){
			v=this.v;
			for(Map<String, Object> map:listData){
				String cycle_type = (String)map.get("cycle_type");
				try {
					if("week".equals(cycle_type)){
						SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						Date endTime = sdf1.parse((String)map.get("end_time"));
//						Calendar calendar=new GregorianCalendar();
//						calendar.setTime(endTime);
//						calendar.add(calendar.DATE,-5);
//						Date validTime = calendar.getTime();
						if(new Date().after(endTime) ){
							Toast toast = Toast.makeText(getApplicationContext(),
							"点检时间已截止，无法点检！", Toast.LENGTH_LONG);
							toast.setGravity(Gravity.CENTER, 0, 0);
							toast.show();
							back(v);
							return;
						}
					}
				} catch (ParseException e) {
					e.printStackTrace();
				}
				StringBuilder sb = null;
				String it_type = (String)map.get("it_type"); 
				String record_id = (String)map.get("check_record_id");
				Object dataException = map.get("is_exception");
				if("√".equals(it_type)){
					sb = new StringBuilder();
					sb.append("update EQ_CHECK_RECORD set IS_EXCEPTION='no' where CHECK_RECORD_ID=?");
					st.execSQL(sb.toString(), new Object[]{record_id});
				}else if("╳".equals(it_type)){
					sb = new StringBuilder();
					sb.append("update EQ_CHECK_RECORD set IS_EXCEPTION='yes' where CHECK_RECORD_ID=?");
					st.execSQL(sb.toString(), new Object[]{record_id});
				}else if("yes".equals(dataException)){
					sb = new StringBuilder();
					sb.append("update EQ_CHECK_RECORD set CHECK_RESULT=?,IS_EXCEPTION='yes' where CHECK_RECORD_ID=?");
					st.execSQL(sb.toString(), new Object[]{it_type, record_id});
				}else{
					sb = new StringBuilder();
					sb.append("update EQ_CHECK_RECORD set CHECK_RESULT=?,IS_EXCEPTION='no' where CHECK_RECORD_ID=?");
					st.execSQL(sb.toString(), new Object[]{it_type, record_id});
				}
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String checkTime = sdf.format(new Date());
				sb = new StringBuilder();
				sb.append("update EQ_CHECK_RECORD set CHECK_USER_ID=?,CHECK_TIME=? where CHECK_RECORD_ID=?");
				st.execSQL(sb.toString(), new Object[]{empId, checkTime, record_id});
			}
			
			listData = getData(cycle_type,belongEq);
			listAdapter.notifyDataSetChanged();
			
			Intent intent = new Intent();  
	        intent.putExtra("tabCode", tabCode);  
	        setResult(2, intent);  
	        finish();
		}else{
			Toast toast = Toast.makeText(getApplicationContext(),
					"请输入数值", Toast.LENGTH_LONG);
			toast.setGravity(Gravity.CENTER, 0, 0);
			toast.show();
		}
		
	}
	
	private String getExpId(String record_id){
		
		Exception obj = st.queryForObject(new RowMapper<Exception>() {

			@Override
			public Exception mapRow(Cursor cursor, int index) {
				Exception exp = new Exception();
				exp.setExceptionSubmitId(cursor.getString(cursor.getColumnIndex("EXCEPTION_SUBMIT_ID")));
				return exp;
			}
		}, "select * from RP_EXCEPTION_SUBMIT where RESOURCE_TYPE=? and RESOURCE_ID=?", new String[]{"dj", record_id});
		
		return obj.getExceptionSubmitId();
	}	
	
	@Override
	public void onBackPressed() {
		back(v);
	}
	
	private boolean judgeScope(String value, Object downValObj, Object upValObj){
		
		if(null==value||"".equals(value)){
			return false;
		}
		
		double val = Double.valueOf(value);
		
		if(null!=downValObj&&null!=upValObj){
			
			double downVal = Double.valueOf(downValObj.toString());
			double upVal = Double.valueOf(upValObj.toString());
			if(val>=downVal&&val<=upVal){
				return true;
			}
		}
		
		if(null==downValObj&&null==upValObj){
			return true;
		}
		if(null==downValObj&&null!=upValObj){
			double upVal = Double.valueOf(upValObj.toString());
			if(val<=upVal){
				return true;
			}
		}
		if(null!=downValObj&null==upValObj){
			double downVal = Double.valueOf(downValObj.toString());
			if(val>=downVal){
				return true;
			}
		}
		return false;
	}
	
	/**
     * 为了得到传回的数据，必须在前面的Activity中（指Tab1Activity类）重写onActivityResult方法
     * 
     * requestCode 请求码，即调用startActivityForResult()传递过去的值
     * resultCode 结果码，结果码用于标识返回数据来自哪个新Activity(CheckItemActivity)
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	// TODO Auto-generated method stub
    	super.onActivityResult(requestCode, resultCode, data);
    	if(resultCode==2){
    		if(requestCode==1){
	    		String belongEq = data.getStringExtra("belongEq"); 
	    		String cycle_type = data.getStringExtra("cycle_type"); 
	    		String listPosStr = data.getStringExtra("position");
	    		if(null!=listPosStr){
	    			Integer listPos = Integer.valueOf(listPosStr) ;
	        		Map map = listData.get(listPos);
	        		map.put("is_exception", "yes");
	        		listAdapter.notifyDataSetChanged();
	    		}
    		}else if(requestCode==3){
    			String belongEq = data.getStringExtra("belongEq"); 
	    		String cycle_type = data.getStringExtra("cycle_type"); 
    			listData = getData(cycle_type,belongEq);
    			listAdapter.notifyDataSetChanged();
    		}
    		
    	}
    	
    }
    
    void clearExceptionInfo() {
    	st = SQLiteTemplate.getInstance(dbManager, false);
		StringBuilder sb = new StringBuilder();
    	sb.append("delete from RP_EXCEPTION_SUBMIT ");
    	sb.append("where RESOURCE_TYPE=? and RESOURCE_ID=?");
    	st.execSQL(sb.toString(), new Object[]{"dj",record_id});
    	sb = new StringBuilder();
    	sb.append("delete from EQ_ATTACHMENT ");
    	sb.append("where TABLE_NAME=? and KEY=? and VALUE=?");
    	st.execSQL(sb.toString(), new Object[]{"RP_EXCEPTION_SUBMIT","EXCEPTION_SUBMIT_ID", exp_id});
	}  
    
}

